package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.GoodsType;
import cn.wolfcode.trip.base.domain.PointMsg;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.mapper.PointMsgMapper;
import cn.wolfcode.trip.base.query.GoodsTypeQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IPointMsgService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class PointMsgServiceImpl implements IPointMsgService {

    @Autowired
    private PointMsgMapper pointMsgMapper;


    public PageInfo<PointMsg> selectForList(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<PointMsg> list = pointMsgMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    public void delete(Long id) {
        pointMsgMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Integer getUnread(Long userId) {
        Integer count = pointMsgMapper.getCount(userId);
        return count;
    }

    @Override
    public void changeRead(Long userId) {
        pointMsgMapper.updateReadByUserId(userId);
    }

    @Override
    public void addSystemMsg(Long userId) {
        User user = new User();
        user.setId(userId);
        PointMsg pointMsg = new PointMsg();
        pointMsg.setUser(user);
        pointMsg.setCreateTime(new Date());
        pointMsg.setMsg("您的酒店已预订成功,更多服务请咨询前台,400-88666888");
        pointMsgMapper.insert(pointMsg);
    }
}
